package net.onceface.core.domain;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import net.onceface.core.domain.mappedsuper.TimeIntervalEntity;
import net.onceface.infra.domain.NamedParameters;

/**
 * 规格类
 * **/
@Entity
@Table(name="SYS_SPEC")
public class Spec extends TimeIntervalEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6219497052685012089L;
	
	/**
	 * 商品id
	 * */
	@Column(name = "PRODUCT_ID")
	private Long productId;
	
	/**
	 * 规格名字
	 * **/
	@Column(name="NAME")
	private String name;
	
	/**
	 * 库存
	 * **/
	@Column(name="STOCK")
	private int stock;
	
	/**
	 * 是否禁用
	 * **/
	@Column(name="DISABLED")
	private boolean disabled;
	
	/**
	 * 商品原价
	 * **/
	@Column(name = "ORIGINAL_PRICE")
	private double originalPrice;
	
	/**
	 * 商品价格
	 * **/
	@Column(name = "PRICE")
	private double price;
	
	/**
	 * 上否上架
	 * **/
	@Column(name="SALE")
	private boolean sale;
	
	/**
	 * 根据id获取合法的规格
	 * **/
	public static Spec getValidSpecById(Long id){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("id", id);
		params.put("sale", true);
		params.put("disabled", true);
		
		return getRepository().getByBusinessKeys(Spec.class, NamedParameters.create(params));
	}

	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public boolean isDisabled() {
		return disabled;
	}


	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}


	public int getStock() {
		return stock;
	}


	public void setStock(int stock) {
		this.stock = stock;
	}


	public Long getProductId() {
		return productId;
	}


	public void setProductId(Long productId) {
		this.productId = productId;
	}


	public double getOriginalPrice() {
		return originalPrice;
	}


	public void setOriginalPrice(double originalPrice) {
		this.originalPrice = originalPrice;
	}


	public double getPrice() {
		return price;
	}


	public void setPrice(double price) {
		this.price = price;
	}


	public boolean isSale() {
		return sale;
	}


	public void setSale(boolean sale) {
		this.sale = sale;
	}


	@Override
	public String[] businessKeys() {
		// TODO Auto-generated method stub
		return null;
	}

}
